home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.3 (Developer)…68k, x86, SPARC, PA-RISC] / NeXTSTEP 3.3 Dev Intel.iso / NextDeveloper / Headers / bsd / ufs / fsdir.h < prev    next >
C/C++ Source or Header  |  1995-02-14  |  3KB  |  86 lines

  1. /* 
  2.  * Mach Operating System
  3.  * Copyright (c) 1987 Carnegie-Mellon University
  4.  * All rights reserved.  The CMU software License Agreement specifies
  5.  * the terms and conditions for use and redistribution.
  6.  **********************************************************************
  7.  * HISTORY
  8.  *  7-Jan-93  Mac Gillon (mgillon) at NeXT
  9.  *    Integrated POSIX changes
  10.  * 24-Jan-89  Peter King (king) at NeXT
  11.  *    NFS 4.0 Changes.  Cleaned out old directory cruft.
  12.  *
  13.  **********************************************************************
  14.  */
  15.  
  16. /* 
  17.  * Copyright (c) 1988 by Sun Microsystems, Inc.
  18.  * @(#) from SUN 2.6; from UCB 4.5 82/11/13
  19.  */
  20.  
  21. /*
  22.  * A directory consists of some number of blocks of DIRBLKSIZ
  23.  * bytes, where DIRBLKSIZ is chosen such that it can be transferred
  24.  * to disk in a single atomic operation (e.g. 512 bytes on most machines).
  25.  *
  26.  * Each DIRBLKSIZ byte block contains some number of directory entry
  27.  * structures, which are of variable length.  Each directory entry has
  28.  * a struct direct at the front of it, containing its inode number,
  29.  * the length of the entry, and the length of the name contained in
  30.  * the entry.  These are followed by the name padded to a 4 byte boundary
  31.  * with null bytes.  All names are guaranteed null terminated.
  32.  * The maximum length of a name in a directory is MAXNAMLEN.
  33.  *
  34.  * The macro DIRSIZ(dp) gives the amount of space required to represent
  35.  * a directory entry.  Free space in a directory is represented by
  36.  * entries which have dp->d_reclen > DIRSIZ(dp).  All DIRBLKSIZ bytes
  37.  * in a directory block are claimed by the directory entries.  This
  38.  * usually results in the last entry in a directory having a large
  39.  * dp->d_reclen.  When entries are deleted from a directory, the
  40.  * space is returned to the previous entry in the same directory
  41.  * block by increasing its dp->d_reclen.  If the first entry of
  42.  * a directory block is free, then its dp->d_ino is set to 0.
  43.  * Entries other than the first in a directory do not normally have
  44.  * dp->d_ino set to 0.
  45.  */
  46. #define DIRBLKSIZ    1024        /* a convenient number */
  47. #if !defined(_MAXNAMLEN)
  48. #define _MAXNAMLEN
  49. #define    MAXNAMLEN    255
  50. #endif /* _MAXNAMLEN */
  51.  
  52. struct    direct {
  53.     u_long    d_ino;            /* inode number of entry */
  54.     u_short    d_reclen;        /* length of this record */
  55.     u_short    d_namlen;        /* length of string in d_name */
  56.     char    d_name[MAXNAMLEN + 1];    /* name must be no longer than this */
  57. };
  58.  
  59. /*
  60.  * The DIRSIZ macro gives the minimum record length which will hold
  61.  * the directory entry.  This requires the amount of space in struct direct
  62.  * without the d_name field, plus enough space for the name with a terminating
  63.  * null byte (dp->d_namlen+1), rounded up to a 4 byte boundary.
  64.  */
  65. #undef DIRSIZ
  66. #define DIRSIZ(dp) \
  67.     ((sizeof (struct direct) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3))
  68.  
  69. #ifdef KERNEL
  70. /*
  71.  * Template for manipulating directories.
  72.  * Should use struct direct's, but the name field
  73.  * is MAXNAMLEN - 1, and this just won't do.
  74.  */
  75. struct dirtemplate {
  76.     u_long    dot_ino;
  77.     short    dot_reclen;
  78.     short    dot_namlen;
  79.     char    dot_name[4];        /* must be multiple of 4 */
  80.     u_long    dotdot_ino;
  81.     short    dotdot_reclen;
  82.     short    dotdot_namlen;
  83.     char    dotdot_name[4];        /* ditto */
  84. };
  85. #endif
  86.